package qhLoading.manager 
{
	import flash.utils.Dictionary;
	
	import qhLoading.LoaderPriority;
	import qhLoading.info.ResourceInfo;
	
	import utils.QhUtils;
	/**
	 * ...
	 * @author gcxk721
	 */
	public class ResourceManager 
	{
		
		private static var _resourceNameMap : Dictionary = new Dictionary();

        public function ResourceManager()
        {

        }

        public static function addResource(info : ResourceInfo) : void
        {
            _resourceNameMap[info.name] = info;
        }

        public static function removeResource(info : ResourceInfo) : void
        {
            delete _resourceNameMap[info.name];
        }

        public static function getInfoByName(name : String) : ResourceInfo
        {
            return _resourceNameMap[name] as ResourceInfo;
        }

        public static function hasInfoByName(name : String) : Boolean
        {
            return name in _resourceNameMap;
        }

		/**
		 * 根据加载优先级 删除资源
		 * 适用于仙域风云
		 *
		 */
		public static function disposeByPriority() : void
		{
			var tmp : ResourceInfo = null;
			for each (tmp in _resourceNameMap)
            {
                
                if (tmp.priority != LoaderPriority.LevelC)
				{
					removeResource(tmp);
					tmp.dispose();
					tmp = null;
				}
            }
            QhUtils.gc();
		}
		
        public static function disposeAll() : void
        {
            var tmp : ResourceInfo = null;
            for each (tmp in _resourceNameMap)
            {
                
                tmp.dispose();
            }
            QhUtils.gc();
        }
		
	}

}